MCU=atmega16
CC=/usr/bin/avr-gcc
OBJCOPY=/usr/bin/avr-objcopy

TARGET=main

# optimize for size:
CFLAGS=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues -pedantic -Wno-long-long

all: $(TARGET).hex
$(TARGET).hex : $(TARGET).out 
	$(OBJCOPY) -R .eeprom -O ihex $(TARGET).out $(TARGET).hex 
$(TARGET).out : $(TARGET).o 
	$(CC) $(CFLAGS) -o $(TARGET).out -Wl,-Map,$(TARGET).map $(TARGET).o 
$(TARGET).o : $(TARGET).c 
	$(CC) $(CFLAGS) -Os -c $(TARGET).c

# erase the AVR before it is programmed
load: $(TARGET).hex
	uisp -dlpt=/dev/parport0 --erase  -dprog=dapa
	uisp -dlpt=/dev/parport0 --upload if=$(TARGET).hex -dprog=dapa  -v=3 --hash=32

clean:
	rm -f *.o *.map *.out *.hex
